/*------------------------------------------------------------------------
 *  Copyright (C) 2010  Luis M. de la Cruz
 *
 *  This file is part of TUNA
 *
 *  TUNA is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  TUNA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 ------------------------------------------------------------------------*/

#ifndef _NUM_UTILS_H_
#define _NUM_UTILS_H_


namespace Tuna {
  
/*!
 ***************************************************************************
 * \namespace NumUtils
 * Algorithms to interpolate scalarfields between nodes, volumes and 
 * staggered meshes.
 ***************************************************************************
 *  \author Luis M. de la Cruz [ Sun Mar 23 15:03:47 GMT 2008 ]
 ***************************************************************************
 */
  namespace NumUtils {

// For Structured Uniform Meshes

    template<typename Tfield>
    void interpolateToVolumes(Tfield &, Tfield &);

    template<typename Tfield>
    void interpolateToNodes(Tfield &, Tfield &);

// For Structured Non-Uniform Meshes

    template<typename Tfield, typename Tmesh>
    void interpolateToNodes(Tfield &, Tfield &, Tmesh &); 

// For Structured Uniform Meshes

    template<typename Tfield> 
    void staggerFromNodesX(Tfield &, Tfield &);  

    template<typename Tfield> 
    void staggerFromNodesY(Tfield &, Tfield &);  

    template<typename Tfield> 
    void staggerFromNodesZ(Tfield &, Tfield &);

// Error, Norms, Etc.
    template<typename Tfield>
    double calcErrorL1(const Tfield&, const Tfield&);

    template<typename Tfield>
    double calcAbsoluteError_L1(const Tfield&, const Tfield&);

    template<typename Tfield>
    double calcErrorL2(const Tfield&, const Tfield&);

    template<typename Tfield>
    double calcAbsoluteError_L2(const Tfield&, const Tfield&);

    template<typename Tfield>
    double calcErrorLmax(const Tfield&, const Tfield&);

    template<typename Tfield>
    double calcAbsoluteError_Lmax(const Tfield&, const Tfield&);

    template<typename Tfield>
    double normL1(const Tfield &);

    template<typename Tfield>
    double normL2(const Tfield &);

    template<typename Tfield>
    double normLmax(const Tfield &);

// Interpolation of velocities on structured uniform meshes
    template<typename Tfield>
    void interpolateToNodesUs(Tfield &, Tfield &);

    template<typename Tfield>
    void interpolateToNodesVs(Tfield &, Tfield &);

    template<typename Tfield>
    void interpolateToNodesWs(Tfield &, Tfield &);

 // Old functions to be deprecated soon...
    template<typename Tfield>
	bool interX(Tfield &, Tfield &); 
 
    template<typename Tfield>
	bool interY(Tfield &, Tfield &);
    
    template<typename Tfield>
	bool interZ(Tfield &, Tfield &); 

// Nusselt number calculation.
    template<typename Tfield>
    double calcNusseltVert(Tfield &, double, double, int);

    template<typename Tfield>
    double calcNusseltHoriz(Tfield &, double, double, int);

    template<typename Tfield>
    double calcNusseltVert(Tfield &, double, double, double, int);

    template<typename Tfield>
    double calcNusseltHoriz(Tfield &, double, double, double, int);


    /*** NO YET REVISED ...
    template<typename Tfield, typename Tmesh>
    void interpolateToNodes(Tmesh &, Tfield &, Tfield &);
    template<typename Tfield, typename Tmesh>
    void interpolateToNodesUs(Tmesh &, Tfield &, Tfield &);
    template<typename Tfield, typename Tmesh>
    void interpolateToNodesVs(Tmesh &, Tfield &, Tfield &);
    template<typename Tfield, typename Tmesh>
    void interpolateToNodesWs(Tmesh &, Tfield &, Tfield &);
    
    *****/


    /**
    template<typename Tfield> 
	bool staggerX(Tfield &, Tfield &);
    template<typename Tfield> 
	bool staggerY(Tfield &, Tfield &);    
    template<typename Tfield> 
	bool staggerZ(Tfield &, Tfield &);
    */

    /*
    template<typename Tfield, typename Tmesh> 
	bool staggerX(Tmesh &, Tfield &, Tfield &);
    template<typename Tfield, typename Tmesh> 
	bool staggerY(Tmesh &, Tfield &, Tfield &);
    template<typename Tfield, typename Tmesh> 
	bool staggerZ(Tmesh &, Tfield &, Tfield &);
    
    template<typename Tfield>
	double getSorsum(Tfield &, Tfield &, double, double);
    template<typename Tfield>
	double getSorsum(Tfield &, Tfield &, Tfield &,
			 double, double, double);    
    template<typename Tfield>
	double getResorm(Tfield &, Tfield &, double, double);    
    template<typename Tfield>
	double getResorm(Tfield &, Tfield &, Tfield &,
			 double, double, double);
    template<typename Tfield>
	double calcNusselt(Tfield &, double, double); 
    template<typename Tfield, typename Tmesh>
	double calcNusseltVert(Tmesh &, Tfield &, int);
    ***/
    
  } // NumUtils namespace

} // Tuna namespace

#include "../src/Utils/num_utils.cpp"

#endif //_NUM_UTILS_H_


